char ch[5] = {'a','e','i','o','u'};
class Solution {
public:
    int countOfSubstrings(string word, int k) {
        int n = word.size(),left1 = 0,left2 = 0,right = 0;
        unordered_map<int,int> mm1;
        unordered_map<int,int> mm2;
        auto fun1 = [&](){
            // 只要合格就退出,返回假
            int cnt = 0;
            for(int i = 0;i <5;i++){
                if(mm1[ch[i]] == 0)return false;
                cnt += mm1[ch[i]];
            }
            return cnt + k < right - left1 + 1;
        };
        auto fun2 = [&](){
            if(left1 > left2) return true;

            // 只要合格就继续,返回真
            int cnt = 0;
            for(int i = 0;i < 5;i++){
                if(mm2[ch[i]] == 0)return false;
                cnt += mm2[ch[i]];
            }
            return cnt + k <= right - left2 + 1;
        };
        int ans = 0;
        while(right < n){
            mm1[word[right]]++;
            mm2[word[right]]++;
            while(fun1()){
                mm1[word[left1]]--;
                left1++;
            }
            while(fun2()){
                mm2[word[left2]]--;
                left2++;
            }
            // cout << left1 <<' ' << left2  << ' ' << right << endl;
            ans+= (left2 - left1);
            right++;
        }
        return ans;
    }
};